/*************************************************************************
	> File Name: 6-3-a.c
	> Author: Angel Criss
	> Mail: abbytsing@gmail.com 
	> Created Time: Fri Jul 25 20:09:30 2014
 ************************************************************************/
// this file simulate setenv() system call

int mysetenv(char *name,char *value, int overwrite)
{
    int i=0;

    char string[100];  // assume the name within 100, there shuold be a limit

    while(name[i]!='=')
    {
        string[i]=name[i];
        i++;
    }
    /* if the name does exist, and overwrite is non-zero
     * ,then old value change the vlaue here
     * */
    if(getenv(string)!=NULL)
    {
        if(overwrite!=0)
            putenv(value);
        else
            return;
    }
    /*
     * if the name does not exist, then adds the variable 'name'
     * to the environment with the value 'value'
     */
    if(getenv(string)==NULL)
    {
        putenv(value);
    }

    return;
}
